import routers from './routers'

const rooterMenus = [
  {
    id: 'projectManage',
    raw: {
      name: '项目管理',
      code: 'projectManage'
    },
    children: [
      {
        id: 'businessExecution',
        raw: {
          name: '业务执行',
          code: 'businessExecution'
        },
        children: [
          {
            id: 'massProduce',
            hasSubMenu: true,
            raw: {
              name: '大生产',
              icon: 'u272',
              code: 'massProduce',
            },
            children: ['PM', 'QM', 'SHE', 'TM', 'PMD', 'STM', 'BIM']
          },
          {
            id: 'economicLine',
            hasSubMenu: true,
            raw: {
              name: '经济线',
              icon: 'u302',
              code: 'economicLine'
            },
            children: ['MM', 'BM', 'LCM']
          },
          {
            id: 'supplyChain',
            raw: {
              name: '供应链',
              icon: 'u305',
              code: 'supplyChain',
            },
          },
          {
            id: 'relateManagement',
            hasSubMenu: true,
            raw: {
              name: '相关方管理',
              icon: 'u308',
              code: 'relateManagement'
            },
            children: ['KF']
          },
          {
            id: 'digitalSite',
            raw: {
              name: '数字工地',
              icon: 'u311',
              code: 'digitalSite'
            },
          },
        ]
      },
      {
        id: 'businessControl',
        raw: {
          name: '业务管控',
          code: 'businessControl'
        },
        children: [
          {
            id: 'massProduce',
            hasSubMenu: true,
            raw: {
              name: '大生产',
              icon: 'u272',
              code: 'massProduce'
            },
            children: ['PM', 'QM', 'SHE', 'TM', 'PMD', 'STM']
          },
        ]
      },
      {
        id: 'businessSearch',
        raw: {
          name: '业务查询',
          code: 'businessSearch'
        },
        children: [
          {
            id: 'massProduce',
            hasSubMenu: true,
            raw: {
              name: '大生产',
              icon: 'u272',
              code: 'massProduce'
            },
            children: ['PM', 'QM', 'SHE', 'TM', 'PMD', 'STM', 'BIM']
          },
          {
            id: 'economicLine',
            hasSubMenu: true,
            raw: {
              name: '经济线',
              icon: 'u302',
              code: 'economicLine'
            },
            children: ['MM', 'BM', 'LCM']
          },
          {
            id: 'supplyChain',
            raw: {
              name: '供应链',
              icon: 'u305',
              code: 'supplyChain'
            }
          },
          {
            id: 'relateManagement',
            hasSubMenu: true,
            raw: {
              name: '相关方管理',
              icon: 'u308',
              code: 'relateManagement'
            },
            children: ['KF']
          },
        ]
      },
    ]
  },
  {
    id: 'syntheticalManage',
    raw: {
      name: '综合管理',
      code: 'syntheticalManage'
    },
    children: ['hr', 'JX', 'BG', 'DQ', 'GH', 'jijian','enterprisePlanning']
  },
  {
    id: 'operateCenter',
    raw: {
      name: '运营中心',
      code: 'operateCenter'
    },
    children: ['sjkb'] //缺少运营决策，数据资产
  },
  {
    id: 'systemManage',
    raw: {
      name: '系统管理',
      code: 'systemManage'
    },
    children: ['SYSMG']
  },
  {
    id: 'userCenter',
    raw: {
      name: '个人中心',
      code: 'userCenter'
    },
    children: ['thi'] //缺少通知信息，个人信息管理
  }
]

export const filterRootMenu = (menus) => {
  // console.log(menus)
  console.log(menus.map(item => ({ name: item.raw.name, code: item.raw.code, children: item.children?.map(i => ({name: i.raw.name, code: i.raw.code})) })))
  return rooterMenus.map(rootMenu => {
    if(rootMenu.raw.code === 'projectManage'){
      return {
        ...rootMenu,
        level: 1,
        children: rootMenu.children.map(secondMenu => ({
          ...secondMenu,
          level: 2,
          children: secondMenu.children.map(item => ({
            ...item,
            level: 2,
            children: menus.filter(menu => item.children?.some(i => i === menu.raw.code)) || []
          }))
        }))
      }
    }else{
      return {
        ...rootMenu,
        children: menus.filter(menu =>rootMenu.children?.some(i => i === menu.raw.code)) || []
      }
    }
  })
}

export default rooterMenus